Command line utilities
File name parts with basename
Filename without path:
FILENAME=`basename /usr/bin/sort`sets FILENAME to sort.
Filename without path and specified extension:
FILENAME=`basename include/stdio.h .h`sets FILENAME to stdio.
String formatting with printf
E.g. print arguments as shell-escaped string:
printf "%q " $*Temporary file or directory with mktemp
The (empty) file or directory is created, with a random name in the temporary directory.
TMPFILE=`mktemp`
TMPDIR=`mktemp -d`To only generate the name but not create the file or directory, add -u.
Follow file from start
tail -n +1 -f
tail -n +1 -f | cmdRun command preventing sleep
systemd-inhibit <command>Convert scans to PDF
convert <images> <output>.pdfThe print size can be controlled via -density 150, uniform size in pixels induced via -extent "2476x3503" -gravity Center.
Distinguish between executable, alias, and function
type <cmd>Edit input lines (e.g. in bash)
Many terminal programs use the readline library for editing input. Options including key bindings are defined in ~/.inputrc:
$include /etc/inputrc
# use arrow up/down to search history
"\e[A": history-search-backward
"\e[B": history-search-forward
# from <https://www.topbug.net/blog/2017/07/31/inputrc-for-humans/>
# and <https://datacadamia.com/lang/bash/edition/inputrc>
set colored-stats On
set completion-ignore-case On
set completion-prefix-display-length 3
set mark-symlinked-directories On
set show-all-if-ambiguous On
set show-all-if-unmodified On
set visible-stats On
set skip-completed-text onThis configuration makes ↑↑ ↓↓ search the history backwards and forwards based on the text before the cursor position.
Ctrl+UCtrl+U delete the input before the cursor position
Ctrl+KCtrl+K delete the input after the cursor position
The combination Ctrl+UCtrl+U Ctrl+KCtrl+K can therefore be used to delete the entire input.
TODO: tr, sed, awk, jq, regex-rename, fd, rg, bat, fzf